package com.RedRiver.hospitalsystem.finance_service.app.controller;


import com.RedRiver.hospitalsystem.finance_service.client.InvoiceClient;
import com.RedRiver.hospitalsystem.finance_service.client.param.*;
import com.RedRiver.hospitalsystem.finance_service.common.WoniuxyBeanCopyUtil;
import com.RedRiver.hospitalsystem.finance_service.infra.mapper.InvoiceMapper;
import com.RedRiver.hospitalsystem.finance_service.service.InvoiceService;
import com.RedRiver.hospitalsystem.finance_service.service.from.CreateInvoiceFrom;
import com.RedRiver.hospitalsystem.finance_service.service.from.FindBillAllForm;
import com.RedRiver.hospitalsystem.finance_service.service.from.FindInvoicePageFromList;
import com.RedRiver.hospitalsystem.finance_service.service.info.CreateInvoiceInfo;
import com.RedRiver.hospitalsystem.finance_service.service.info.FindBillAllListInfo;
import com.RedRiver.hospitalsystem.finance_service.service.info.FindInvoiceInfo;
import com.RedRiver.hospitalsystem.finance_service.service.info.FindInvoiceListInfo;
import com.RedRiver.hospitalsystem.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 龙世超
 * @since 2022-04-26
 */
@RestController
@RequestMapping("/invoice")
@Api(tags = "发票")
public class InvoiceController implements InvoiceClient {

    @Resource
    private InvoiceService invoiceService;

    //新建发票
    @ApiOperation("/新建发票")
    @PostMapping("/createInvoice")
    public Result<CreateInvoiceInfoClient> createInvoice(@RequestBody CreateInvoiceFromClient createInvoiceFromClient) {
        CreateInvoiceFrom copyone = WoniuxyBeanCopyUtil.copyone(createInvoiceFromClient, CreateInvoiceFrom.class);
        CreateInvoiceInfo createInvoiceInfo=invoiceService.createInvoice(copyone);
        CreateInvoiceInfoClient copyone1 = WoniuxyBeanCopyUtil.copyone(createInvoiceInfo, CreateInvoiceInfoClient.class);
        return Result.getInstance(CreateInvoiceInfoClient.class).setData(copyone1);
    }

    //分页查询所有发票
    @ApiOperation("分页查询所有发票")
    @PostMapping("/findInvoiceAll")
    public Result<FindInvoiceAllListInfoClient> findInvoiceAll(@RequestBody FindInvoicePageFromListClient findInvoicePageFromListClient) {
        FindInvoicePageFromList copyone = WoniuxyBeanCopyUtil.copyone(findInvoicePageFromListClient, FindInvoicePageFromList.class);
        FindInvoiceListInfo findInvoiceListInfo=invoiceService.findInvoiceAll(copyone);
        FindInvoiceAllListInfoClient copyone1 = WoniuxyBeanCopyUtil.copyone(findInvoiceListInfo, FindInvoiceAllListInfoClient.class);
        return Result.getInstance(FindInvoiceAllListInfoClient.class).setData(copyone1);
    }

    //发票换开
    @ApiOperation("/发票换开")
    @PostMapping("/changeInvoice")
    public Result<CreateInvoiceInfoClient> changeInvoice(@RequestBody CreateInvoiceFromClient createInvoiceFromClient) {
        CreateInvoiceFrom copyone = WoniuxyBeanCopyUtil.copyone(createInvoiceFromClient, CreateInvoiceFrom.class);
        CreateInvoiceInfo createInvoiceInfo=invoiceService.changeInvoice(copyone);
        CreateInvoiceInfoClient copyone1 = WoniuxyBeanCopyUtil.copyone(createInvoiceInfo, CreateInvoiceInfoClient.class);
        return Result.getInstance(CreateInvoiceInfoClient.class).setData(copyone1);
    }
}

